package org.univ.fblikes;

/**
 * User: dzirtbry
 * Date: 5/18/13
 * Time: 5:38 PM
 */
public class Word implements Comparable<Word> {
    private final String key;
    private int count;

    public Word(String key) {
        this.key = key;
        count = 0;
    }

    public Word(String key, int count) {
        this.key = key;
        this.count = count;
    }

    public String getKey() {
        return key;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int compareTo(Word o) {
        if (o == null) {
            return -1;
        }
        int compare = Integer.compare(o.getCount(), this.getCount());
        // If scores are equals - sort in alphabetic order (ignore case)
        return compare == 0 ? this.getKey().toLowerCase().compareTo(o.getKey().toLowerCase()) : compare;
    }
}
